`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date: 2024/11/02 18:11:05
// Design Name: 
// Module Name: top
// Project Name: 
// Target Devices: 
// Tool Versions: 
// Description: 
// 
// Dependencies: 
// 
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
// 
//////////////////////////////////////////////////////////////////////////////////


module top(
    input                   sys_clk_pin_i               ,


    //AS5047P 磁编码器 SPI接口 IO
    output                  as5047p_spi_ss_pin_o        ,     
    output                  as5047p_spi_sck_pin_o       ,    
    output                  as5047p_spi_mosi_pin_o      ,   
    input                   as5047p_spi_miso_pin_i      ,

    //AS5047P 磁编码器 ABI接口 IO
    input                   as5047p_A_pin_i             ,
    input                   as5047p_B_pin_i             ,
    input                   as5047p_I_pin_i             ,
    //AD7928 ADC IO
    output                  ad7928_cs_pin_o             ,
    output                  ad7928_sclk_pin_o           ,
    output                  ad7928_mosi_pin_o           ,
    input                   ad7928_miso_pin_i           ,

    //无刷电机驱动 IO
    output                  svpwm_en_pin_o              ,
    output                  svpwm_u_pin_o               ,
    output                  svpwm_v_pin_o               ,
    output                  svpwm_w_pin_o               ,

    //UART IO
    output                  uart_tx_pin_o               ,
    //LED IO
    output                  led_pin_o                       
);

wire sys_clk_i  ;
wire sys_clk_40M_i;
wire sys_rst_n_i;


wire signed[31:0]      foc_Iq_aim_i                     ;
wire signed[31:0]      foc_Iq_pid_p_i                   ;
wire signed[31:0]      foc_Iq_pid_i_i                   ;
wire signed[31:0]      foc_Id_aim_i                     ;
wire signed[31:0]      foc_Id_pid_p_i                   ;
wire signed[31:0]      foc_Id_pid_i_i                   ;
wire signed[31:0]      foc_speed_aim_i                  ;
wire signed[31:0]      foc_speed_pid_p_i                ;
wire signed[31:0]      foc_speed_pid_i_i                ;
wire signed[31:0]      foc_position_aim_i               ;
wire signed[31:0]      foc_position_pid_p_i             ;
wire signed[31:0]      foc_position_pid_i_i             ;
wire[7:0]              wavedata_sel_i                   ;


clk_wiz_0  clk_wiz_0_1
 (
  // Clock out ports
  .clk_out1     (   sys_clk_i           ),
  .clk_out2     (   sys_clk_40M_i       ),
  // Status and control signals
  .locked       (   sys_rst_n_i         ),
 // Clock in ports
  .clk_in1      (   sys_clk_pin_i       )
 );


wire[31:0]     foc_mode;
wire[31:0]     foc_calibration_en;
wire signed[31:0]      foc_open_uq_i             ;
wire signed[31:0]      foc_open_ud_i             ;



vio_0 vio_01(
    .clk        (    sys_clk_i                  ),
    .probe_out0 (    foc_mode                   ),
    .probe_out1 (    foc_calibration_en         ),
    .probe_out2 (    foc_open_uq_i              ),
    .probe_out3 (    foc_open_ud_i              ),
    .probe_out4 (    foc_Iq_aim_i               ),
    .probe_out5 (    foc_Iq_pid_p_i             ),
    .probe_out6 (    foc_Iq_pid_i_i             ),
    .probe_out7 (    foc_Id_aim_i               ),
    .probe_out8 (    foc_Id_pid_p_i             ),
    .probe_out9 (    foc_Id_pid_i_i             ),
    .probe_out10(    foc_speed_aim_i            ),
    .probe_out11(    foc_speed_pid_p_i          ),
    .probe_out12(    foc_speed_pid_i_i          ),
    .probe_out13(    foc_position_aim_i         ),
    .probe_out14(    foc_position_pid_p_i       ),
    .probe_out15(    foc_position_pid_i_i       ),
    .probe_out16(    wavedata_sel_i             )

);



//led呼吸灯
led_breathe led_breathe_hp(
    .sys_clk_i                      (      sys_clk_i                   ),
    .sys_rst_n_i                    (      sys_rst_n_i                 ),
    .led_o                          (      led_pin_o                   )
);


motor_top motor_top_hp(   
    .sys_clk_i                      (      sys_clk_i                    ),
    .sys_rst_n_i                    (      sys_rst_n_i                  ),

    //外部配置参数输入
    .foc_mode_i                     (      foc_mode                     ),
    .foc_calibration_en_i           (      foc_calibration_en           ),
    .foc_open_uq_i                  (      foc_open_uq_i                ),
    .foc_open_ud_i                  (      foc_open_ud_i                ),
    .foc_Iq_aim_i                   (      foc_Iq_aim_i                 ),
    .foc_Iq_pid_p_i                 (      foc_Iq_pid_p_i               ),
    .foc_Iq_pid_i_i                 (      foc_Iq_pid_i_i               ),
    .foc_Id_aim_i                   (      foc_Id_aim_i                 ),
    .foc_Id_pid_p_i                 (      foc_Id_pid_p_i               ),
    .foc_Id_pid_i_i                 (      foc_Id_pid_i_i               ),
    .foc_speed_aim_i                (      foc_speed_aim_i              ),
    .foc_speed_pid_p_i              (      foc_speed_pid_p_i            ),
    .foc_speed_pid_i_i              (      foc_speed_pid_i_i            ),
    .foc_position_aim_i             (      foc_position_aim_i           ),
    .foc_position_pid_p_i           (      foc_position_pid_p_i         ),
    .foc_position_pid_i_i           (      foc_position_pid_i_i         ),

    .wavedata_sel_i                 (       wavedata_sel_i              ),

    //串口
    .uart_tx_pin_o                  (       uart_tx_pin_o               ),


    //adc pin
    .ad7928_cs_pin_o                (       ad7928_cs_pin_o             ),
    .ad7928_sclk_pin_o              (       ad7928_sclk_pin_o           ),
    .ad7928_mosi_pin_o              (       ad7928_mosi_pin_o           ),
    .ad7928_miso_pin_i              (       ad7928_miso_pin_i           ),


    //as5047p spi 接口
    .as5047p_spi_ss_pin_o           (      as5047p_spi_ss_pin_o         ),     
    .as5047p_spi_sck_pin_o          (      as5047p_spi_sck_pin_o        ),    
    .as5047p_spi_mosi_pin_o         (      as5047p_spi_mosi_pin_o       ),   
    .as5047p_spi_miso_pin_i         (      as5047p_spi_miso_pin_i       ),
    //as5047p ABZ 接口
    .as5047p_A_pin_i                (       as5047p_A_pin_i             ),
    .as5047p_B_pin_i                (       as5047p_B_pin_i             ),
    .as5047p_I_pin_i                (       as5047p_I_pin_i             ),

    //电机UVW引脚输出
    .svpwm_en_o                     (       svpwm_en_pin_o              ),
    .svpwm_u_pin_o                  (       svpwm_u_pin_o               ),
    .svpwm_v_pin_o                  (       svpwm_v_pin_o               ),
    .svpwm_w_pin_o                  (       svpwm_w_pin_o               )
);
endmodule
